﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using WGLGridView;
using DBAccessor.Accessor;
using AlanUtilities;
using DBList.Entities;
using DBList;
using System.Collections.Generic;

public partial class NullifyDetails : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		operaterLabel.Text = @"";
		String strUID = OperateControl.PickupAvaiableUserID(this);
		operaterLabel.Text = strUID;
		if (!IsPostBack)
		{
			BindGrideView(null, null);
		}
	}
	private void ShowEmptyRecord()
	{
		string[] fields = { "BarCode", "KindName", "SingleMoney", "MDIntroduction", "ApplyTime", "WLDanHao" };
		WGLGridView.WGLGridView.ClearAndShowEmptyGridView(GridView1, fields);
	}
	protected void AspNetPager1_PageChanged(object sender, EventArgs e)
	{
		string strBegin, strEnd;
		GetSearchTime(out strBegin, out strEnd);
		BindGrideView(strBegin, strEnd);
	}
	protected void BindGrideView(string strBegin, string strEnd)
	{
		string kindmatch = tbKind.Text.Trim();
		int noutTotal = 0;
		MsgAccessor msgAcce = new MsgAccessor();
		List<F123HisData> listData = msgAcce.GetNullifyDetail(AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, strBegin, strEnd, out noutTotal, kindmatch);
		GridView1.DataSource = listData;
		AspNetPager1.RecordCount = noutTotal;
		if (listData.Count == 0)
		{
			ShowEmptyRecord();
		}
		else
		{
			GridView1.DataBind();
		}
		recLabel.Text = @"时间段 总记录：";
		recLabel.Text += noutTotal.ToString();
		recLabel.Text += @" 条";
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onclick", "GridView_selectRow(this)");
			e.Row.Height = 25;
		}
		else if (e.Row.RowType == DataControlRowType.Header)
		{
			e.Row.Height = 25;
		}
	}
	private void GetSearchTime(out string strBegin, out string strEnd)
	{
		DateTime	bdt, edt;
		strBegin = tbBeginTime.Text.Trim();
		strEnd = tbEndTime.Text.Trim();
		if (DateTime.TryParse(strBegin, out bdt))
		{
			if (strEnd.Length == 0)
			{
				edt = DateTime.Now;
			}
			else if (DateTime.TryParse(strEnd, out edt))
			{
				strEnd = edt.ToShortDateString();
				strEnd += @" 23:59:59";
				DateTime.TryParse(strEnd, out edt);
			}
			else
			{
				return;
			}
			strBegin = bdt.ToString();
			strEnd = edt.ToString();
		}
		else if (strBegin.Length == 0 && DateTime.TryParse(strEnd, out edt))
		{
			strEnd = edt.ToShortDateString();
			strEnd += @" 23:59:59";
			DateTime.TryParse(strEnd, out edt);
			strBegin = edt.Year.ToString();
			strBegin += "-01-01 00:00:01";
			DateTime.TryParse(strBegin, out bdt);
		}
		else
		{
			strBegin = strEnd = @"";
		}
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		string strBegin, strEnd;
		GetSearchTime(out strBegin, out strEnd);
		AspNetPager1.CurrentPageIndex = 1;
		BindGrideView(strBegin, strEnd);
	}
}
